//
//  SearchResultViewController.m
//  TripGo
//
//  Created by dllo on 15/7/18.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SearchResultViewController.h"
#import "AFNetworkHandler.h"
#import "TravelTableViewCell.h"
#import "TravelViewController.h"
#import "UIViewController+Example.h"
#import "MJRefresh.h"
#import "TravelPushViewController.h"
#import "SegmentedControl.h"
#import "NoteResultViewController.h"
#import "DestinationsResultViewController.h"

@interface SearchResultViewController () <UIScrollViewDelegate>
@property (nonatomic, retain) UISegmentedControl *seg;
@property (nonatomic, retain) UIScrollView *scrollViewMain;
@end

@implementation SearchResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.seg = [[UISegmentedControl alloc] initWithItems:@[@"游记", @"旅游地"]];
    self.seg.frame = CGRectMake(30, 10, self.view.frame.size.width - 60, 30);
    self.seg.tintColor = [UIColor colorWithRed:56 / 255.0 green:152 / 255.0 blue:135 / 255.0 alpha:1];
    [self.seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    self.seg.selectedSegmentIndex = 0;
    [self.view addSubview:self.seg];
    [_seg release];
    [self setScrollView];
    [self setNotesResultVc];
    [self setDestinationResultVc];
    
    
    // Do any additional setup after loading the view.
}
- (void)segAction:(UISegmentedControl *)seg
{
    if (seg.selectedSegmentIndex == 0) {
        self.scrollViewMain.contentOffset = CGPointMake(0, 0);
    } else {
        self.scrollViewMain.contentOffset = CGPointMake(self.view.frame.size.width, 0);
    }
}
- (void)setScrollView
{
    self.scrollViewMain = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 30)];
    self.scrollViewMain.showsVerticalScrollIndicator = NO;
    self.scrollViewMain.delegate = self;
    self.scrollViewMain.pagingEnabled = YES;
    self.scrollViewMain.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height - 30);
    [self.view addSubview:self.scrollViewMain];
    [_scrollViewMain release];
}
- (void)setNotesResultVc
{
    NoteResultViewController *notesRvc = [[NoteResultViewController alloc] init];
    notesRvc.isHiden = YES;
    notesRvc.name = self.name;
    notesRvc.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
    [self addChildViewController:notesRvc];
    [self.scrollViewMain addSubview:notesRvc.view];
    [notesRvc didMoveToParentViewController:self];
    [notesRvc release];
}
- (void)setDestinationResultVc
{
    DestinationsResultViewController *desRvc = [[DestinationsResultViewController alloc] init];
    desRvc.isHiden = YES;
    desRvc.view.frame = CGRectMake(self.view.frame.size.width * 1, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
    [self addChildViewController:desRvc];
    [self.scrollViewMain addSubview:desRvc.view];
    [desRvc didMoveToParentViewController:self];
    [desRvc release];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger index =  scrollView.contentOffset.x / self.view.frame.size.width;
    if (index == 0) {
        self.seg.selectedSegmentIndex = 0;
    } else if (index == 1) {
        self.seg.selectedSegmentIndex = 1;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
